package io.kiki.stack.netty.command;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
//@Setter
@Getter
public enum ResponseType {
    success, // Ok
    error, // Error caught
    server_exception, // Exception caught
    unknown, // Unknown...
    server_threadpool_busy, // Process thread pool busy
    error_comm, // Error of communication
    no_processor, // No processor find
    timeout, // Timeout
    client_send_error, // Send failed
    codec_exception, // Exception in encode or decode
    channel_closed, // channel closed.
    server_serial_exception, // server serialize exception
    server_deserial_exception // server deserialize exception
    ;


    public static ResponseType valueOf(short value) {
        switch (value) {
        case 0x0000:
            return success;
        case 0x0001:
            return error;
        case 0x0002:
            return server_exception;
        case 0x0003:
            return unknown;
        case 0x0004:
            return server_threadpool_busy;
        case 0x0005:
            return error_comm;
        case 0x0006:
            return no_processor;
        case 0x0007:
            return timeout;
        case 0x0008:
            return client_send_error;
        case 0x0009:
            return codec_exception;
        case 0x0010:
            return channel_closed;
        case 0x0011:
            return server_serial_exception;
        case 0x0012:
            return server_deserial_exception;
        }
        throw new IllegalArgumentException("Unknown status value ," + value);
    }


    public short getValue() {
        switch (this) {
        case success:
            return 0x0000;
        case error:
            return 0x0001;
        case server_exception:
            return 0x0002;
        case unknown:
            return 0x0003;
        case server_threadpool_busy:
            return 0x0004;
        case error_comm:
            return 0x0005;
        case no_processor:
            return 0x0006;
        case timeout:
            return 0x0007;
        case client_send_error:
            return 0x0008;
        case codec_exception:
            return 0x0009;
        case channel_closed:
            return 0x0010;
        case server_serial_exception:
            return 0x0011;
        case server_deserial_exception:
            return 0x0012;

        }
        throw new IllegalArgumentException("Unknown status," + this);
    }
}
